#include <windows.h>
#include <iostream>

bool IsMouseSideButtonPressed() {
    return (GetAsyncKeyState(VK_XBUTTON1) & 0x8000) != 0;
}

void SimulateKeyPress(WORD vk) {
    INPUT input[2] = {0};
    
    // 按下按键
    input[0].type = INPUT_KEYBOARD;
    input[0].ki.wVk = vk; // 虚拟键码
    input[0].ki.dwFlags = 0; // 0表示按下
    SendInput(1, input, sizeof(INPUT));
    
    // 释放按键
    input[1].type = INPUT_KEYBOARD;
    input[1].ki.wVk = vk;
    input[1].ki.dwFlags = KEYEVENTF_KEYUP; // KEYEVENTF_KEYUP表示释放
    SendInput(1, input + 1, sizeof(INPUT));
}

int main() {
    while (true) {
        if (IsMouseSideButtonPressed()) {
            std::cout << "鼠标侧键被按下" << std::endl;
            SimulateKeyPress(VkKeyScan('t'));
        }
        Sleep(100); // 每0.1秒检查一次
    }
    return 0;
}